<?php 
	include_once '../../include/inc_session.php';
	require_once('../../utils/fonctions.php');
	
	if(isset($_GET['idcontrat']))
	{
		$_SESSION['idcontrat'] = $_GET['idcontrat'];
	}
	
	if(isset($_GET['modcontrac']))
	{
		$urlJavascript = '../modcontract/editpersonne.php';
		$url = "../modcontract/index.php";
		$urlAdd = '../modcontract/addtpersonne.php';
	}
	else //normalement le cas if(isset($_SESSION['chgmtcouv']))
	{
		$urlJavascript = 'edit_personne.php';
		$url = "../changecouverture/index.php";
		$urlAdd = 'add_personne.php';
	}//on ne gere pas encore un autre cas
	unset($_SESSION['visu']);
	unset($_SESSION['idRolePers']); unset($_SESSION['IdRolePers']);
	unset($_SESSION['IdPers']);
	
	
	if (isset($_SERVER['QUERY_STRING'])) 
	{
	  $url .= "?" . htmlentities($_SERVER['QUERY_STRING']."&recherche=0");
	  $urlAdd .= "?" . htmlentities($_SERVER['QUERY_STRING']);
	  $urlJavascript .= "?" . $_SERVER['QUERY_STRING']."&Identifiant_personne=";
	}
	else
	{
		$url .= "?recherche=0";
	  	$urlJavascript .= "?Identifiant_personne=";
	}
	
	$oPersonne = new dataObject_personne();

	if ((isset($_POST["MM_rechercher"])) && ($_POST["MM_rechercher"] == "form1")) 
	{
	
		$maxRows_rs1 = 10;
		$pageNum_rs1 = 0;
		
		if (isset($_GET['pageNum_rs1'])) 
		{
		  $pageNum_rs1 = $_GET['pageNum_rs1'];
		}
		
		$startRow_rs1 = $pageNum_rs1 * $maxRows_rs1;
		$rs1 = $oPersonne->personne_search($_POST['Type_personne'], $_POST['Nom_personne'], $_POST['Prenom_personne'], $_POST['Date_naissance_personne'], $startRow_rs1, $maxRows_rs1 );
		$num = count($rs1);
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Recherche personne</title>
<link rel="stylesheet" type="text/css" href="../../css/main.css" />
<link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->



<script language="Javascript">
<!--
                
    function modifiercontrat(choix)
    {
        var modifActcontrat = document.getElementById("modifActcontrat");
        modifActcontrat.href = <?php echo "'".$urlJavascript."'" ?> + choix ;
    }
                
    function afficher(choix){
        var tesmed_err = document.getElementById("tesmed_err");
        tesmed_err.href = 'recherchepersonne.php?Identifiant_personne=' + choix + '&valid=1';
    }
 //-->
</script>
</head>

<body>
	<div id="sf_menu1">
	<h3>Production </h3>
	<div id="information_erreur" class="false">
        <ul id="message">
        	<li><?php $aMsg =$oForm->getValidMessage(); echo (!empty($aMsg))? $aMsg[0]['message'] : ''; ?></li>
        </ul>
<?php
	
	$nommodule="Recherche personne";
	$nom_module_saisie="Ecran saisie";

?>
</div>
</div>
<div class="cleared"></div>
<div class="corps1">
<?php 
	require('../index.php');
	if(isset($message) && !empty($message))
	{
		echo $message;
	}
?>

<form action="<?php echo $sEditFormAction; ?>" method="post" name="form1" id="form1">

 	<div class="imgleft"></div>
	<div class="imgmiddle">
	    <div class="btn">
	    	<span class="btnleft"></span>
	        <span class="btnmiddle">
	        	<h5><?php echo $nommodule; ?></h5>
	        </span><span class="btnright"></span>
	    </div>
	  	<div class="btn1">
	    	<span class="btnleft"></span>
	        <span class="btnmiddle">
	        	<h5><?php echo $nom_module_saisie; ?></h5>
	        </span>
	        <span class="btnright"></span>
	    </div>
    
		<div class="formulaire">
  <table class="tabform">
      <tr>
      <td  class="td0">TYPE </td>
      <td>
      
      <select name="Type_personne" id="Type_personne"  >
      <?php 
      $requete = dataObject_elementdico::elementdico_getListFromCode(dataObject_dictionnaire::_TYPE_PERSONNE);
      
	  foreach($requete as $iKey => $reponse )
	  {  
      	if(isset($_SESSION['Type_personne'])) 
        	echo "<option ".remind_select1('Type_personne', $reponse["Code_element"]) ; 
        else 
        	echo "<option ".remind_select('Type_personne',$reponse["Code_element"]);
        echo "value='".$reponse["Code_element"]."'>";
        echo $reponse["Nom_element"]."</option>";?>
        
        <?php 
	  }?>
        </select>
      
          </td>
    </tr>
    <tr >
      <td class="td0">NOM </td>
      <td><input class="resize_2"  type="text" name="Nom_personne" value="<?php echo remind_text('Nom_personne'); ?>" size="32" maxlength="30" /></td>
    </tr>
    <tr >
      <td class="td0">PRENOM</td>
      <td><input class="resize_2" type="text" name="Prenom_personne" value="<?php echo remind_text('Prenom_personne'); ?>"  size="32"  maxlength="30" /></td>
    </tr>
    <tr>
      <td class="td0">DATE NAISSANCE </td>
      <td><input class="date" type="text" name="Date_naissance_personne" value="<?php echo remind_text('Date_naissance_personne'); ?>" size="10" />&nbsp;</td>
    </tr> 
    </table>
    
    	</div> 
		<div class="bt1 bn"> <span class="btleft"></span>
		    <input type="submit" value="Rechercher" name="Rechercher" class="btmiddle"/>
	        <span class="btright"></span>
	    </div>
	</div> 
	
	<div class="imgright"></div>				
	<div class="cleared"></div>

<h3>RESULTAT RECHERCHE </h3>
<div class="cleared"></div>
 <div class="imgleft"></div>
	<div class="imgmiddle">

<table class="tab_liste">
  <tr id="niv1">
   <td class="td0">&nbsp;</td>
    <td class="td1">NOM</td>
    <td class="td2">PRENOM</td>
    <td class="td4">DATE NAISSANCE</td>
    <td class="td5">LIEU NAISSANCE</td>
    <td>SEXE</td>
  </tr>
</table>

<div class="content_table bright">
  <table class="tab_list">
  
<?php 
	$i=1; 
	if(isset($num) && $num>0) 
	{//SI DES PERSONNES ONT ÉTÉ TROUVÉES
		foreach($rs1 as $iKey1 => $row_rs1)
	  	{
	  		if(isset($row_rs1['Type_personne']) && !empty($row_rs1['Type_personne']))
	  		{
?>
	    	<tr <?php if($i%2==0) echo 'class="colorligne"'; ?>>
	    
	    	<td class="td0">
	    	<?php
	  	
			if ((isset($_POST["Rechercher"])) && isset($_SESSION['idcontrat']))
			{
		   			echo'<input onClick="modifiercontrat(this.value);" type="radio" id="choix" name="choix" value="'.$row_rs1['Identifiant_personne'].'" />';
			}
			else
			{
		    	echo'<input onClick="afficher(this.value);" type="radio" id="choix" name="choix" value="'.$row_rs1['Identifiant_personne'].'" />';  
			} 	 
		 	?>
		     </td>
		      
		      <td class="td1"><?php if($row_rs1['Type_personne']=="P")echo $row_rs1['Nom_personne']; else echo $row_rs1['Raison_sociale']?></td>
		      <td class="td2"><?php echo $row_rs1['Prenom_personne']; ?></td>
		      <td class="td4"><?php echo dateEN2FR($row_rs1['Date_naissance_personne']); ?></td>
		      <td class="td5"><?php echo $row_rs1['Lieu_naissance_personne']; ?></td>
		      <td><?php  if($row_rs1['Sexe_personne']=='F') echo "F&eacute;minin" ; elseif($row_rs1['Sexe_personne']=='M') echo "Masculin" ; ?></td>
		    </tr>
		    <?php 
				$ty_pers = $row_rs1['Type_personne'];
				echo '<input type="hidden" name="Type_personne" value="'.$ty_pers.'" />';
			} 
			$i++;
		} 
	}
?>
	</table>
</div>
<div class="cleared"></div>
</div>

<div class="imgright"></div>				
<div class="cleared"></div>
				
<?php
	
	
	/*if(isset($_GET["valid"]))
	{	
		echo '<div class="bt1"><a href="index.php"><span class="btleft"></span><span class="btmiddle">Retour</span><span class="btright"></span></a></div>';
	}
	else*/ 
	//if(isset($_GET['modcontrac']) || isset($_SESSION['chgmtcouv'])){
		echo '<div class="bt1"><a href="'.$urlAdd.'"><span class="btleft"></span><span class="btmiddle">Retour</span><span class="btright"></span></a></div>';
	/*
	}
	else
	{	
		echo'<div class="bt1"><a href="'.$url.'"><span class="btleft"></span><span class="btmiddle">Retour</span><span class="btright"></span></a></div>';
	}*/
					
	if (isset($_POST["Rechercher"]) && isset($_SESSION['idcontrat']))
	{ 
		echo '<div class="bt"><a id="modifActcontrat" href="#"><span class="btleft"></span><span class="btmiddle">Valider</span><span class="btright"></span></a></div>';
	}
	else
	{
		echo '<div class="bt"><a id="tesmed_err" href="#"><span class="btleft"></span><span class="btmiddle">Valider</span><span class="btright"></span></a></div>';
	}	
?>
						
		<div class="cleared"></div>
		<input type="hidden" name="Identifiant_personne" value="" />
		<input type="hidden" name="MM_rechercher" value="form1" />
</form>
</div>
</body>
</html>
<?php
include_once PATH_INCLUDE.'inc_pied_page.php';
?>
